/**
 * @file factory_mode_gcf.c
 *
 */

/*********************
 *      INCLUDES
 *********************/
#include "lv_watch.h"

#if USE_LV_WATCH_FACTORYMODE_GCF!= 0

#include <stdio.h>

/*********************
 *      DEFINES
 *********************/

/**********************
 *      TYPEDEFS
 **********************/

/**********************
 *  STATIC PROTOTYPES
 **********************/
static void gcf_btn_press_action(lv_obj_t * btn, lv_event_t event);
static void gcf_prepare_destory(lv_obj_t * activity_obj);

/**********************
 *  STATIC VARIABLES
 **********************/

/**********************
 *      MACROS
 **********************/

/**********************
 *   GLOBAL FUNCTIONS
***********************/
lv_obj_t * factorymode_gcf_create(lv_obj_t * activity_obj)
{
    lv_obj_t * obj;
    if(activity_obj == NULL) {
        lv_watch_activity_ext_t activity_ext;
        memset(&activity_ext, 0, sizeof(lv_watch_activity_ext_t));
        activity_ext.actId = ACT_ID_FACTORY_MODE_GCF;
        activity_ext.create = factorymode_gcf_create;
        activity_ext.prepare_destory = gcf_prepare_destory;
        activity_obj = lv_watch_creat_activity_obj(&activity_ext);
        LV_ASSERT_MEM(activity_obj);
        if(NULL == activity_obj) {
            return NULL;
        }
    }

    obj = lv_watch_obj_create(activity_obj);
    LV_ASSERT_MEM(obj);
    if(NULL == obj) {
        return NULL;
    }

    //title
    lv_obj_t * title = lv_label_create(obj, NULL);
    lv_obj_set_size(title, LV_HOR_RES, LV_VER_RES / 6);
    lv_label_set_text_id(title, WATCH_TEXT_ID_GCF);
    lv_obj_add_style(title, LV_LABEL_PART_MAIN, &lv_watch_font20);
    lv_obj_align(title, NULL, LV_ALIGN_IN_TOP_MID, 0, 5);

    //button
    lv_obj_t * btn = lv_btn_create(obj, NULL);
    lv_obj_set_size(btn, LV_HOR_RES * 2 / 3, 40);
    lv_obj_align(btn, NULL, LV_ALIGN_IN_TOP_LEFT, 10, 35);
    lv_obj_set_event_cb(btn, gcf_btn_press_action);

    lv_obj_t * label = lv_label_create(btn, NULL);
    if(false == gcf_test) {
        lv_label_set_text_id(label, WATCH_TEXT_ID_START_TEST);
    } else {
        lv_label_set_text_id(label, WATCH_TEXT_ID_STOP_TEST);
    }
    lv_obj_add_style(label, LV_LABEL_PART_MAIN, &lv_watch_font20);

    return obj;
}

/**********************
 *   STATIC FUNCTIONS
 **********************/
static void gcf_btn_press_action(lv_obj_t * btn, lv_event_t event)
{
    if(LV_EVENT_PRESSED != event) return;

    lv_obj_t * label = lv_obj_get_child(btn, NULL);

    if(false == gcf_test) {
        gcf_test = true;
        lv_label_set_text_id(label, WATCH_TEXT_ID_STOP_TEST);
    } else {
        gcf_test = false;
        lv_label_set_text_id(label, WATCH_TEXT_ID_START_TEST);
    }
    lv_obj_add_style(label, LV_LABEL_PART_MAIN, &lv_watch_font20);

    printf("%s: gcf_test = %d\n", __FUNCTION__, gcf_test);
    return;
}

static void gcf_prepare_destory(lv_obj_t * activity_obj)
{
    lv_watch_png_cache_all_free();
}

#endif /*USE_LV_WATCH_FACTORY_MODE*/
